package com.jinmei.utils;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;


public final class JDBCUtility {
	
	private final static String ORACLE = "oracle";
	private final static String MYSQL = "mysql";
	private final static String MYSQL_DRIVER = "com.mysql.jdbc.Driver";
	private final static String MYSQL_URL = "jdbc:mysql://localhost:3306/yscn";
	private final static String MYSQL_USER = "root";
	private final static String MYSQL_PWD = "admin";
	
	private final static String ORACLE_DRIVER = "oracle.jdbc.driver.OracleDriver";
	private final static String ORACLE_URL = "jdbc:oracle:thin:@127.0.0.1:1521:test01";
	private final static String ORACLE_USER = "scott";
	private final static String ORACLE_PWD = "tiger";
	
	public static Connection getConnection(String dbType){
		Connection conn = null;
		if(ORACLE.equals(dbType)){
			try {
				Class.forName(ORACLE_DRIVER);
				conn = (Connection) DriverManager.getConnection(ORACLE_URL,ORACLE_USER,ORACLE_PWD);
			} catch (ClassNotFoundException e) {
				System.out.println("class not found!");
				e.printStackTrace();
			}catch(SQLException e) { 
			    e.printStackTrace(); 
			} 
			
		}
		if(MYSQL.equals(dbType)){
			try {
				Class.forName(MYSQL_DRIVER);
				conn = (Connection) DriverManager.getConnection(MYSQL_URL,MYSQL_USER,MYSQL_PWD);
			} catch (ClassNotFoundException e) {
				System.out.println("class not found driver!");
				e.printStackTrace();
			}catch(SQLException e) { 
			    e.printStackTrace(); 
			} 
			
		}
		
		return conn;
	}
}
